import os
import sys
import paddle

file_name = sys.argv[1]
# file_name= '2.m4a';
name = os.path.splitext(file_name)[0]
output_file_name = './output/'+name
video_path = './input/'+file_name

# os.remove(output_file_name+'.wav')

def audio2wav(audio_path, output_name):
    output_name = output_name + '.wav'
    os.system("ffmpeg -i " + audio_path + " -ac 1 -ar 16000" + " " + output_name)

audio2wav(video_path, output_file_name)


from paddlespeech.cli import ASRExecutor, TextExecutor

asr_executor = ASRExecutor()
text_executor = TextExecutor()

text = asr_executor(
            audio_file = output_file_name+'.wav',
                device=paddle.get_device())
result = text_executor(
            text=text,
                task='punc',
                    model='ernie_linear_p3_wudao',
                        device=paddle.get_device())
print('语音转文字\n{}'.format(result))
